﻿
using Net.http;
using PacketDotNet;
using System;
namespace HBase {
    public class TaskUtil {
        private static Object lockObj = new Object();
        private const int arang = 0x7FFFFF;
        private static int TaskNo = -1;
        public static int getTaskNo() {
            lock( lockObj ) {
                if( TaskNo == -1 ) {
                    TaskNo = getTime();
                } else {
                    TaskNo++;
                    int minTime = getTime() - 3600;
                    if( minTime < 0 ) {
                        minTime = minTime + arang;
                    }
                    if( TaskNo < minTime ) {
                        TaskNo = minTime;
                    }
                    if( TaskNo >= arang ) {
                        TaskNo -= arang;
                    }
                }
                return TaskNo + 1000000000;
            }
        }
        static private int getTime() {
            long seconds = System.DateTime.Now.Ticks / HUtil.ticksSecRate;
            int Task = ( int ) (seconds & arang);
            return Task;
        }

        private static Object lockObj2 = new Object();
        static  int q=1000; 
        public static uint getQuee(TcpPacket  tcp ) {
            int b = 1;
            if (tcp == null||tcp.PayloadData==null||tcp.PayloadData.Length==0) {
                b = 1;
            } else {
                b = tcp.PayloadData.Length;
            }
            if (b == 0) {
            
            }
            lock (lockObj2) {
                if (q > int.MaxValue-8) {
                    q = 1000;
                }
                q += b;
                return (uint)(q-b);
            }
        
        }

    }
}
